package com.example.soscall.utils;

import android.bluetooth.BluetoothAdapter;

//import com.ecarx.log.Lg;


public class BluetoothUtil {

    public static String TAG = BluetoothUtil.class.getSimpleName();

    private static boolean isBluetoothChanged = false;

    public static boolean openBluetooth() {
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        if (btAdapter != null) {
            if (!btAdapter.isEnabled() && isBluetoothChanged) {
                isBluetoothChanged = false;
                return btAdapter.enable();
            }

        }
        return false;
    }

    public static boolean closeBluetooth() {
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        if (btAdapter != null) {
            if (btAdapter.isEnabled() && !isBluetoothChanged) {
                isBluetoothChanged = true;
                return btAdapter.disable();
            }
        }
        return false;
    }

    public static boolean isBluetoothConnected() {

        boolean isConnected = false;
        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();

        if ((btAdapter.getState() == BluetoothAdapter.STATE_ON) && (btAdapter.getBondedDevices().size() > 0)) {
            isConnected = true;
        }

        return isConnected;
    }

}
